package student.design_pattern.chain_zeren_pattern;

public abstract class AbstractLogger {

    public static int INFO = 1;
    public static int DEBUG = 2;
    public static int ERROR = 3;

    protected int level;

    /**
     * 责任链中的下一个元素
     */
    protected AbstractLogger nextLogger;

    public void setNextLogger(AbstractLogger nextLogger) {
        this.nextLogger = nextLogger;
    }

    /**
     * 打印
     *
     * @param level   level
     * @param message message
     */
    public void logMessage(int level, String message) {
        // 找到合适的lever开始打印
        if (this.level <= level) {
            write(message);
        }
        // 继续传递给下个打印器
        if (nextLogger != null) {
            nextLogger.logMessage(level, message);
        }
    }

    abstract protected void write(String message);
}